//
//  SearchBaseView.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/11/17.
//  Copyright © 2017年 bob. All rights reserved.
//

#import "SearchBaseView.h"

@interface SearchBaseView()<UITextFieldDelegate>

@property(nonatomic,copy)SearchChangeBlock block;

@end

@implementation SearchBaseView

-(instancetype)initWithFrame:(CGRect)frame andBlock:(SearchChangeBlock)SearchBlock
{
    if (self=[super initWithFrame:frame]) {
        
        self=[[[NSBundle mainBundle]loadNibNamed:@"SearchBaseView" owner:self options:nil]lastObject];
        self.frame=frame;
        
        self.BgView.layer.cornerRadius=8.0;
        
        self.BgView.layer.masksToBounds=YES;
   
        [self.SearchTF addTarget:self action:@selector(EditChange:) forControlEvents:UIControlEventEditingChanged];
        
        self.SearchTF.returnKeyType=UIReturnKeyDone;
        
        _block=SearchBlock;
        
        self.SearchTF.delegate=self;
        
    }
    
    return self;
}

- (IBAction)CancleAction:(UIButton *)sender {
    
    _block(@"",YES);
    
}

-(void)EditChange:(UITextField*)tf
{
    
    _block(tf.text,NO);
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    
    return YES;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
